package cn.hanyx.coder.design.pattern.behavioral.state.demo03;

import cn.hanyx.coder.design.pattern.behavioral.state.demo03.state.IMario;
import cn.hanyx.coder.design.pattern.behavioral.state.demo03.state.SmallMario;
import cn.hanyx.coder.design.pattern.behavioral.state.demo03.state.State;

/**
 * MarioStateMachine
 * <p>
 * 状态机实现方式二：查表法
 * <p>
 * 对于状态很多、状态转移比较复杂的状态机来说，查表法比较合适。
 * 通过二维数组来表示状态转移图，能极大地提高代码的可读性和可维护性
 * <p>
 * 像游戏
 *
 * @author hanyx
 * @date 2020/06/08
 */
public class MarioStateMachine {
    private int score;
    private IMario currentState;

    public MarioStateMachine() {
        score = 0;
        currentState = SmallMario.getInstance();
    }

    /**
     * 碰到蘑菇
     */
    public void obtainMushRoom() {
        this.currentState.obtainMushRoom(this);
    }

    /**
     * 碰到斗篷
     */
    public void obtainCape() {
        this.currentState.obtainCape(this);
    }

    /**
     * 获得火焰
     */
    public void obtainFireFlower() {
        this.currentState.obtainFireFlower(this);
    }

    /**
     * 碰到怪物
     */
    public void meetMonster() {
        this.currentState.meetMonster(this);
    }

    public int getScore() {
        return score;
    }

    public State getCurrentState() {
        return currentState.getName();
    }

    public void setScore(int score) {
        this.score = score;
    }

    public void setCurrentState(IMario currentState) {
        this.currentState = currentState;
    }
}
